package ru.aslanov.schedule.client.ds;

import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.fields.DataSourceEnumField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.FieldType;
import com.smartgwt.client.widgets.form.validator.MaskValidator;
import ru.aslanov.schedule.shared.DayOfWeek;

import java.util.LinkedHashMap;

/**
 * Created by IntelliJ IDEA.
 * Created: Feb 3, 2010 12:46:47 PM
 *
 * @author Sergey Aslanov
 */
public class ScheduleItemsDS extends BaseDS {
    private static ScheduleItemsDS instance = null;

    public static ScheduleItemsDS getInstance() {
        if (instance == null) {
            instance = new ScheduleItemsDS("ScheduleItem", null);
        }
        return instance;
    }


    public ScheduleItemsDS(String id, InputLangProvider inputLangProvider) {
        super(id, inputLangProvider);

        DataSourceTextField group = new DataSourceTextField("group");
        group.setHidden(true);

        DataSourceEnumField dayOfWeek = new DataSourceEnumField("dayOfWeek", cnt.dayOfWeekField(), 15);
        dayOfWeek.setRequired(true);
        final LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
        for (DayOfWeek day : DayOfWeek.values()) {
            map.put(day.name(), cnt.daysOfWeek()[day.ordinal()]);
        }
        dayOfWeek.setValueMap(map);

        final MaskValidator maskValidator = new MaskValidator();
        maskValidator.setMask("\\d\\d:\\d\\d");

        DataSourceField startTime = new DataSourceField("startTime", FieldType.TEXT, cnt.startTimeField(), 10, true);
        startTime.setValidators(maskValidator);

        DataSourceField endTime = new DataSourceField("endTime", FieldType.TEXT, cnt.endTimeField(), 10, true);
        endTime.setValidators(maskValidator);

        DataSourceField location = new DataSourceField("locationKey", FieldType.TEXT, cnt.locationField());
        //location.setForeignKey("Location.encodedKey");

        //DataSourceTextField googleEventId = new DataSourceTextField("googleEventId", "Gcal event ID");

        setFields(encodedKey, group, dayOfWeek, startTime, endTime, location/*, locationName*/);
    }
}
